<template>
  <div>
    <h1>订单详情</h1>
    <div>
      <div>
        <el-divider content-position="left">普通订单</el-divider>
      </div>
      <div>订单编号：{{ orderInfo.orderNo }}</div>
    </div>
    <!-- 订单信息 -->
    <div style="margin-top: 20px">
      <el-descriptions :column="4" direction="vertical">
        <el-descriptions-item label="订单信息" width="100px">{{
          orderInfo.prodInfo
        }}</el-descriptions-item>
        <el-descriptions-item label="订单金额" width="100px">{{
          orderInfo.orderAmount
        }}</el-descriptions-item>
        <el-descriptions-item label="创建时间" width="100px">{{
          orderInfo.createTime
        }}</el-descriptions-item>
        <el-descriptions-item label="订单状态" width="100px">
          <span v-if="orderInfo.orderStatus == 0">未支付</span>
          <span v-if="orderInfo.orderStatus == 1">已支付</span>
          <span v-if="orderInfo.orderStatus == 2">待发货</span>
        </el-descriptions-item>
      </el-descriptions>
    </div>
    <!-- tab表格 -->
    <div>
      <el-tabs type="border-card">
        <el-tab-pane label="订单信息">
          <div>
            <el-divider direction="vertical" style="color: orange" />
            <span>用户信息</span>
            <div>
              <el-descriptions>
                <el-descriptions-item label="用户ID">{{
                  user.userId
                }}</el-descriptions-item>
                <el-descriptions-item label="用户昵称">{{
                  user.userName
                }}</el-descriptions-item>
                <el-descriptions-item label="联系方式">{{
                  user.userMobile
                }}</el-descriptions-item>
              </el-descriptions>
            </div>
            <el-divider border-style="dashed" />
          </div>
          <div>
            <el-divider direction="vertical" style="color: orange" />
            <span>订单信息</span>
            <div>
              <el-descriptions>
                <el-descriptions-item label="商品总价">{{
                  orderInfo.orderAmount
                }}</el-descriptions-item>
                <el-descriptions-item label="上级推广人"
                  >无</el-descriptions-item
                >
              </el-descriptions>
            </div>
          </div>
        </el-tab-pane>
        <el-tab-pane label="商品信息">
          <el-table :data="detailList" stripe style="width: 100%">
            <el-table-column prop="prodId" label="商品ID" width="70" />
            <el-table-column prop="prodName" label="商品名称" width="100" />
            <el-table-column prop="buyPrice" label="商品价格" width="80" />
            <el-table-column prop="buyNum" label="购买数量" width="80" />
            <el-table-column prop="costPrice" label="成本价" width="80" />
            <el-table-column prop="prodStock" label="库存" width="80" />
            <el-table-column prop="prodImage" label="图片" width="100">
              <template #default="scope">
                <el-image
                  :src="scope.row.prodImage"
                  style="width: 50px; height: 50px"
                />
              </template>
            </el-table-column>
            <el-table-column prop="amount" label="小计" width="100" />
            <el-table-column label="操作" />
          </el-table>
        </el-tab-pane>
        <el-tab-pane label="订单记录">
          <el-table :data="recordList" stripe style="width: 100%">
            <el-table-column prop="recordId" label="序号" width="100" />
            <el-table-column prop="optRecord" label="操作记录" width="180" />
            <el-table-column prop="createTime" label="操作时间" width="180" />
          </el-table>
        </el-tab-pane>
        <el-tab-pane label="发货记录">Task</el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";
import { getOrderInfoById } from "../api/api";

const orderInfo = ref({
  orderNo: "",
  prodInfo: "",
  orderAmount: "",
  createTime: null,
  orderStatus: null,
});
const user = ref({
  userId: null,
  userName: "",
  userMobile: "",
});
const detailList = ref([]);
const recordList = ref([]);

onMounted(() => {
  let orderId = sessionStorage.getItem("orderId");
  getOrderInfoById(orderId).then((res) => {
    if (res.data.code == 200) {
      orderInfo.value = res.data.data;
      user.value = res.data.data.user;
      detailList.value = res.data.data.detailList;
      recordList.value = res.data.data.recordList;
    }
  });
});
</script>

<style scoped></style>
